package com.sgb.kjwl.view.ui.adapter.home;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.transport.GoodsSourcesEntity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;
import com.swgk.core.util.DateUtils;
import com.swgk.core.util.StringUtil;

import java.util.List;

public class SourceOfSupplyAdapter extends BaseRecycleAdapter<GoodsSourcesEntity> {

    public SourceOfSupplyAdapter(Context context, List<GoodsSourcesEntity> datas) {
        super(context, R.layout.item_source_of_supply, datas);
    }

    @Override
    public void convert(ItemViewHolder holder, final GoodsSourcesEntity entity) {
        holder.setBinding(BR.viewModel, entity);

        TextView textView = holder.getItem().findViewById(R.id.tv_distance);
        TextView tvTag=holder.getItem().findViewById(R.id.tv_tag);
        TextView tvType=holder.getItem().findViewById(R.id.company_view);
        try{
            if(!TextUtils.isEmpty(entity.getCarLenName())&&!TextUtils.isEmpty(entity.getCarModelName())){
                tvType.setText(entity.getCarModelName() + "/" +entity.getCarLenName() + "  装货:"+ DateUtils.stampToMonthDay(entity.getShipmentTime())+"-"+DateUtils.stampToMonthDay(entity.getShipmentEndTime()));
            }else if(TextUtils.isEmpty(entity.getCarLenName())&&!TextUtils.isEmpty(entity.getCarModelName())){
                tvType.setText(entity.getCarModelName() + "  装货:"+DateUtils.stampToMonthDay(entity.getShipmentTime())+"-"+DateUtils.stampToMonthDay(entity.getShipmentEndTime()));
            }else if(TextUtils.isEmpty(entity.getCarLenName())&&!TextUtils.isEmpty(entity.getCarModelName())){
                tvType.setText(entity.getCarLenName() + "  装货:"+DateUtils.stampToMonthDay(entity.getShipmentTime())+"-"+DateUtils.stampToMonthDay(entity.getShipmentEndTime()));
            }else{
                tvType.setText("装货:"+DateUtils.stampToMonthDay(entity.getShipmentTime())+"-"+DateUtils.stampToMonthDay(entity.getShipmentEndTime()));
            }
        }catch (Exception e){

        }
        if (entity != null) {
            if(TextUtils.isEmpty(entity.getDistance())){
                textView.setText("");
            }else{
                textView.setText(Double.valueOf(entity.getDistance())<1000?"1km以内": StringUtil.fromatUpDistance(entity.getDistance())+"KM");
            }
            if(entity.getPattern()==0){
                tvTag.setVisibility(View.GONE);
            }else{
                tvTag.setVisibility(View.VISIBLE);
            }
        }
    }

}
